package com.xiashitech.agent.instrumentation.bridge;

import com.xiashitech.agent.dto.UserRequest;
import com.xiashitech.agent.instrumentation.base.context.TraceContextVars;
import com.xiashitech.agent.instrumentation.base.context.XSBaggage;
import com.xiashitech.agent.instrumentation.base.context.XSContext;
import com.xiashitech.agent.rule.usermatch.base.UserInfoMatchRule;
import io.opentelemetry.javaagent.shaded.io.opentelemetry.api.baggage.Baggage;
import io.opentelemetry.javaagent.shaded.io.opentelemetry.context.Context;

import java.util.Optional;

public final class Java8Bridge {
    public static <REQUEST> Optional<UserRequest> executeRuleForUserInfoMatchRule(REQUEST request) {
        return UserInfoMatchRule.executeRule(request);
    }

    public static Baggage currentForBaggage() {
        return Baggage.current();
    }

    public static XSBaggage currentForXSBaggage() {
        return XSBaggage.current();
    }

//    public static BridgeBaggage currentForBridgeBaggage() {
//        return BridgeBaggage.current();
//    }

    public static Baggage fromContextForBaggage(Context context) {
        return Baggage.fromContext(context);
    }

    public static XSContext currentForXSContext() {
        return XSContext.current();
    }

    public static String getUserIdFromXSBaggage() {
        return XSBaggage.userIdThreadLocal.get();
    }

    public static void setUserIdToXSBaggage(String userId) {
        XSBaggage.userIdThreadLocal.set(userId);
    }

    public static TraceContextVars currentForTraceContextVars() {
        return TraceContextVars.get();
    }
}
